import time

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
from faker import Faker
from selenium.webdriver.common.by import By
from d11 import *
faker = Faker(locale='zh_cn')
name = faker.name()


class CRMEB:
    def __init__(self,url,driver):
        self.url=url
        self.driver=driver
    def open_driver(self):
        self.driver.get(self.url)
        self.driver.maximize_window()
    def login(self,user,password):
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(user)).send_keys(user)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(password))[ 1].send_keys(password)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(denglu)).click()
        sleep(3)
    def addUserGroup(self):
        # 点击用户tap
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(userIcon))[1].click()
        # 点击用户分组
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(userGroup)).click()
        sleep(2)
        # 点击添加分组
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(addGroupIcon)).click()
        sleep(1)
        # 输入分组名称
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(inputGroupUser))[2].send_keys(
            str(name))
        # 点击确定按钮
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(acceptIcon))[-1].click()
        sleep(3)  # 等待刚新增的分组加上去了

    def deleteGroup(self):
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(shanchu)).click()
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(queding))[2].click()
        sleep(7)
if __name__ == '__main__':
    driver = webdriver.Chrome()
    c1 = CRMEB(driver=driver,url='http://121.43.29.41:8899/admin/login')
    c1.open_driver()
    c1.login('admin','admin123.')
    c1.addUserGroup()
    c1.deleteGroup()


